package com.wsc.goods.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 基础配置
 */
@Configuration
@EnableSwagger2
public class BaseConfig {

    /**
     * 分页插件
     * @return 分页对象
     */
    @Bean
    public PaginationInterceptor getPage(){
        PaginationInterceptor page = new PaginationInterceptor();
        return page;
    }

    /**
     * 自动生成前端文档接口
     * @return
     */
    public Docket getDocket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApi()).select()
                .apis(RequestHandlerSelectors.basePackage("com.wsc.goods.controller"))
                .paths(PathSelectors.any()).build();
    }

    public ApiInfo getApi(){
        return new ApiInfoBuilder().title("商品接口").description("商品文档说明").contact(new Contact("wsc","","wsc"))
                .version("1.0").build();
    }
}
